import 'package:flutter/material.dart';

void main() => runApp(HomePage());

class HomePage extends StatefulWidget {
  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> with SingleTickerProviderStateMixin {

  Animation<double> _doubleAnimation;
  AnimationController _animationController;
//  String _animationValue = "0.0";

  @override
  void initState() {
    super.initState();
    _animationController = AnimationController(vsync: this, duration: const Duration(seconds: 2));
    _doubleAnimation = Tween(begin: 0.0, end: 1.0).animate(_animationController)
      ..addListener(() {
        print(_doubleAnimation.value.toString());
        setState(() {
//          _animationValue = _doubleAnimation.value.toString();
        });
      })
      ..addStatusListener((status) {
        print('status == $status');
      });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: Text("animation1"),),
        body: Center(
          // ??= 如果值为空才赋值
//          child: Text(_animationValue ??= ""),
          child: Text(_doubleAnimation.value.toString()),
        ),
        floatingActionButton: FloatingActionButton(
          onPressed: () {
            _animationController.forward(from: 0.0);
          },
          child: Icon(Icons.play_arrow),),
      ),

    );
  }

  @override
  void dispose() {
    super.dispose();
    // 释放动画内存
    _animationController?.dispose();
  }
}


